package com.yunshu.yunshuapp;

import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import com.fasterxml.jackson.databind.JsonNode;
import com.yunshu.yunshuapp.network.YSCallback;
import com.yunshu.yunshuapp.network.YSRequest;
import com.yunshu.yunshuapp.user.YSUser;
import com.yunshu.yunshuapp.utils.YSUtils;

import org.w3c.dom.Text;

import java.util.HashMap;

public class FeedbackActivity extends AppCompatActivity {

    private TextView textView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_feedback);
        NavigationBar navigationBar = (NavigationBar)findViewById(R.id.navigationBar);
        navigationBar.putInActivity(this);
        navigationBar.setTitle("意见反馈");

        textView = (TextView)findViewById(R.id.editText);
        Button btn = (Button)findViewById(R.id.submitBTN);
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                onSubmit();
            }
        });
    }

    private void onSubmit() {
        String txt = textView.getText().toString();
        if (txt == null || txt.length() == 0){
            YSUtils.showToastOn(this, "请输入反馈内容");
            return;
        }
        HashMap params = new HashMap();
        params.put("content",txt);
        params.put("type","0");
        params.put("asker", YSUser.instance().getPhone());

        new YSRequest(this).POST(YSRequest.Feedback, params, new YSCallback() {
            @Override
            public void onResponse(int isSuccess, JsonNode result) {
                if (isSuccess == YSRequest.REQUEST_OK){
                    tellSendOK();
                }
            }
        });
    }

    private void tellSendOK() {

        new AlertDialog.Builder(this).setTitle("提示")//设置对话框标题

                .setMessage("反馈内容发送成功，感谢您的宝贵意见")//设置显示的内容 ;
                .setPositiveButton("确定",new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {//确定按钮的响应事件
                        finish();
                    }
                }).show();
    }

}

